﻿/*===文件上传Start===*/
var FileUpload = Class.create();
FileUpload.prototype = {
    //宽度
    width: 80,
    //是否自动上传，默认true
    auto: true,
    //Flash路径
    swf: '/Content/uploadify/uploadify.swf',
    //上传地址
    url: "",
    //上传按钮名称
    buttonText: "选择文件",
    //上传按钮图片
    buttonImage: null,
    //上传按钮样式
    buttonClass: '',
    //是否多文件上传，默认单文件
    multi: false,
    //附带表单数据，如{ "objUploadSet": $('#file_upload').attr("data-options") }
    formData: {},
    //提交到服务端的Name名称
    fileObjName: "FileData",
    //上传文件后缀
    fileTypeExts: '*.*',
    //上传文件大小，默认不限制
    fileSizeLimit: 0,
    //上传文件数量
    uploadLimit: 0,
    //上传进度自定义模板
    itemTemplate: "",
    //上传成功事件
    uploadSuccess: function (objFile, objInvokeResult) { },
    //上传完成事件
    uploaded: function () {
        return true;
    },
    //初始化配置
    uploadify: function (setts) {
        setts = setts || {};
        $this = this;
        var defaultSetts = {
            width: 80,
            auto: $this.auto,
            swf: $this.swf,
            uploader: $this.url,
            buttonText: $this.buttonText,
            buttonImage: $this.buttonImage,
            buttonClass: $this.buttonClass,
            multi: $this.multi,
            formData: $this.formData,
            fileObjName: $this.fileObjName,
            fileTypeExts: $this.fileTypeExts,
            fileSizeLimit: $this.fileSizeLimit,
            uploadLimit: $this.uploadLimit,
            //itemTemplate: '<div class="uploadifive-queue-item"><span class="filename"></span> | <span class="fileinfo"></span><div class="close"></div></div>',
            itemTemplate: $this.itemTemplate,
            onUploadSuccess: function (objFile, objInvokeResult) {
                if (JSON.parse) {
                    objInvokeResult = JSON.parse(objInvokeResult);
                } else {
                    objInvokeResult = eval("(" + objInvokeResult + ")");
                }
                $this.uploadSuccess(objFile, objInvokeResult);
                $this.uploaded();
            }
        };
        $.extend(true, defaultSetts, setts);
        $(this.selector).uploadify(defaultSetts);
    },
    //构造函数
    initialize: function (selector) {
        this.selector = selector;
    }
};
/*===文件上传End===*/